package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.NoticeRequestDTO;
import com.tianya.domain.vo.NoticeVO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/26 13:06
 * @description NoticeController
 */
@Api("公告管理")
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @ApiOperation("创建公告")
    @PostMapping
    public Results createNotice(@RequestBody NoticeRequestDTO noticeRequestDTO) {
        noticeService.createNotice(noticeRequestDTO);
        return Results.success();
    }

    @ApiOperation("获取所有通知")
    @GetMapping("/list")
    public Results<List<NoticeVO>> listNotice() {
        List<NoticeVO> noticeVOList = noticeService.listNotice();
        return Results.success(noticeVOList);
    }

    @ApiOperation("分页获取公告")
    @PostMapping("/page")
    public Results<PageResultVO<NoticeVO>> pageNotice(@RequestParam(defaultValue = "1") Integer pageNum,
                                                      @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResultVO<NoticeVO> pageResultVO = noticeService.pageNotice(pageNum, pageSize);
        return Results.success(pageResultVO);
    }

    @ApiOperation("查看详情")
    @GetMapping("/detail/{id}")
    public Results<NoticeVO> getNotice(@PathVariable Long id) {
        NoticeVO noticeVO = noticeService.getNotice(id);
        return Results.success(noticeVO);
    }

    @ApiOperation("编辑公告")
    @PutMapping
    public Results updateNotice(@RequestBody NoticeRequestDTO noticeRequestDTO) {
        noticeService.updateNotice(noticeRequestDTO);
        return Results.success();
    }

    @ApiOperation("删除公告")
    @DeleteMapping("/{id}")
    public Results deleteNotice(@PathVariable Long id) {
        noticeService.removeById(id);
        return Results.success();
    }
}
